<?PHP
/*
    Contact Form from HTML Form Guide
    This program is free software published under the
    terms of the GNU Lesser General Public License.
    See this page for more info:
    http://www.html-form-guide.com/contact-form/php-contact-form-tutorial.html
*/
require_once('./app/fgcontactform.php');
require_once('./app/captcha-creator.php');
require_once('./config.php');

global $ADMIN_EMAIL;

$client_ip = $_SERVER['REMOTE_ADDR'];

$formproc = new FGContactForm();
$captcha = new FGCaptchaCreator('scaptcha');

$submittedInfo = $_POST['submitted'];
$formproc->EnableCaptcha($captcha);

//1. Add your email address here.
//You can add more than one receipients.
$formproc->AddRecipient($ADMIN_EMAIL); //<<---Put your email address here


//2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
// and put it here
$formproc->SetFormRandomKey('n91LqHNvMrpoXte');


if(isset($submittedInfo)) {
   if($formproc->ProcessForm()) {
        include_once("./includes/content/contact_thanks.php");
   }
}

?>

<?php if (!isset($submittedInfo)): ?>
<div class="TexturedText"><img class="Center" src="./app/text.php?text=Contact%20Us" alt="Contact Us" /></div>

<!-- Form Code Start -->
<form id='contactus' action='./index.php?action=contact' method='post' accept-charset='UTF-8'>
    <fieldset>
        <legend align="left">E-mail</legend>
        
        <input type='hidden' name='submitted' id='submitted' value='1'/>
        <input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
        <input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />     
        <div class='short_explanation'>* required fields</div>
        
        <?php if ($formproc->GetErrorMessage()): ?>
            <div class='error'><?php echo $formproc->GetErrorMessage(); ?></div>
        <?php endif; ?>
        
        <div class='container'>
            <label for='name'>* Your Full Name:</label>
            <input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br /><br />
            <div id='contactus_name_errorloc' class='error FloatLeft error2'></div>
        </div>
        
        <div class='container'>
            <label for='email'>* Email Address:</label>
            <input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br /><br />
            <div id='contactus_email_errorloc' class='error FloatLeft error2'></div>
        </div>
        
        <div class='container messageField'>
            <fieldset>
                <legend align="left">Message:</legend>
                <div id='contactus_message_errorloc' class='error'></div>
                <textarea name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
            </fieldset>
        </div>
        
        <div class='container CaptchaArea'>
            <div><img alt='Captcha image' src='./app/show-captcha.php?rand=1' id='scaptcha_img' /></div>
            <label for='scaptcha' id="captchaLabel">Enter the code here:</label>
            <input type='text' name='scaptcha' id='scaptcha' maxlength="10" /><br /><br />
            
            <div id='contactus_scaptcha_errorloc' class='error'></div>
            
            <div class='short_explanation ClearFloats'>
                Can't read the image? <a href='javascript: refresh_captcha_img();'>Click here to refresh</a>.
            </div>
        </div>
        
        
        <div class='container'>
            <input class="button" type='submit' name='Submit' value='Submit' />
        </div>    
    </fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->

<script type='text/javascript'>
// <![CDATA[

    var frmvalidator  = new Validator("contactus");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();
    frmvalidator.addValidation("name","req","Please provide your name.");

    frmvalidator.addValidation("email","req","Please provide your email address.");

    frmvalidator.addValidation("email","email","Please provide a valid email address.");

    frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");


    frmvalidator.addValidation("scaptcha","req","Please enter the code in the image.");

    document.forms['contactus'].scaptcha.validator
      = new FG_CaptchaValidator(document.forms['contactus'].scaptcha,
                    document.images['scaptcha_img']);

    function SCaptcha_Validate()
    {
        return document.forms['contactus'].scaptcha.validator.validate();
    }

    frmvalidator.setAddnlValidationFunction("SCaptcha_Validate");

    function refresh_captcha_img()
    {
        var img = document.images['scaptcha_img'];
        img.src = img.src.substring(0,img.src.lastIndexOf("?")) + "?rand="+Math.random()*1000;
    }

// ]]>
</script>
<?php endif; ?>